import pandas as pd
import numpy as np

# 读取清洗后的数据
df_Master = pd.read_csv('F:\\数据\\df_Master.csv', encoding='gb18030')

# 统计变量总数
print("原变量总数：", len(df_Master.columns))

# 排除目标变量和标识列
cols = [col for col in df_Master.columns if col not in ('target', 'sample_status')]
print("排除目标标签和标识列后的变量数：", len(cols))

# 筛选单变量取值占比>90%的低信息变量
drop_cols_simple = []
for col in cols:
    if max(df_Master[col].value_counts())/len(df_Master)>0.9:
        drop_cols_simple.append(col)
print(f"低信息变量数: {len(drop_cols_simple)}")
print("低信息变量列表:", drop_cols_simple)

# 删除低信息变量
df_Master = df_Master.drop(drop_cols_simple, axis=1).reset_index(drop=True)

# 分离分类变量与数值变量
objectcol = df_Master.select_dtypes(include=["object"]).columns
numcol = df_Master.select_dtypes(include=[np.float64]).columns


#1.排除目标变量和标识列
#2.识别并且删除低信息量特征 单一值占比>90%
#3.分离数值型和类别型特征